package com.syht.wechatpay.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tencent.common.GetOpenId;
import com.tencent.common.WeiXinOauth2Token;
import com.tencent.protocol.pay_protocol.ScanPayReqData;
import com.tencent.service.ScanPayService;

@Controller
@RequestMapping("wechat")
public class WeChartController {

	public WeChartController(){
		
		System.out.println("进入初始化了");
	}
	
	@RequestMapping("/pays")
	public void Pay1(HttpServletRequest request, HttpServletResponse response){
		
		String appid = "wx6e282be064c6b239";
		String appSecret = "85c96eea9e5cc54cf2aa9a5bffeeca4c";
		String code = "031D5lH71SB4iX11ihI71FldH71D5lH2";
		//https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6e282be064c6b239&redirect_uri=http://www.19ea.com/com/aaa&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
		WeiXinOauth2Token wx = GetOpenId.getOauth2AccessToken(appid, appSecret, code);
		System.out.println(wx.getOpenId());
		
		String spBillCreateIP = "192.168.1.7";
		String body = "下单测试";
		String attach = "附加数据";
		String outTradeNo = "20160804000001";
		String totalMoney = "1";
		String timeStart = "20160804112010";
		String timeExpire = "20160804112510";
		String goodsTag = "WXG";
		String deviceInfo = "001";
		Integer totalFee = totalMoney.isEmpty() ? 0 : Integer.valueOf(totalMoney);
		
		try {
			ScanPayService scanPayService = new ScanPayService();
			ScanPayReqData scanPayReqData = new ScanPayReqData(body, attach, outTradeNo, totalFee, deviceInfo, spBillCreateIP, timeStart, timeExpire, goodsTag);
			scanPayService.request(scanPayReqData);
//			httpsRequest(requestUrl, "GET", null);
		} catch (Exception e) {

			e.printStackTrace();
		}
	}
	
}
